package org.visionlibrary.image.filters.adjustement;

import org.visionlibrary.image.model.PixelFilter;

public class Contrast extends PixelFilter {
	double increase;

	public Contrast() {
		this(2.0d);
	}

	public Contrast(double increase) {
		this.increase = increase;
	}

	protected int getNewPixelVal(int value) {
		double res = (double)value / 255d; //zawezam do 0 .. 1
		res -= 0.5d; //przesuwam tak by wartosci byly pomiedzy -.5 i .5
		res *= increase;
		res += 0.5d;
		res *= 255d;
		if(res > 255)
			return 255;
		else if(res < 0)
			return 0;
		else
			return (int)res;
	}

	public double getIncrease() {
		return increase;
	}

	public void setIncrease(double increase) {
		this.increase = increase;
	}
}
